// *****************************************************************************
// CHANGE LOG
//
// *****************************************************************************

#include <p32xxxx.h>
#include "Gpio.h"
#include "Enumerations.h"
#include <plib.h>
/*! \brief Initializes a GPIO resource for control of a specific port
 *
 * Initializes a GPIO resource for control of a specific port and creates
 * a vector of Pin resources.
 *
 * @param port GPIO Port
 */
Gpio::Gpio(Enums::Gpio::Ports port)
{
	this->Port = port;

	// Initialize Pins array setting each pin as an input
	for (int i = 0; i < Enums::Gpio::Pins::PinCountPerPort; i++)
	{
		this->Pins[i] = Pin(port, (Enums::Gpio::Pins::Number)i, Enums::Gpio::Pins::Direction::Input);
	}
}

/*! \brief Releases resources used by the GPIO instance.
 *
 * Frees GPIO resources and sets all pins on the port to their default of
 * digital inputs.
 */
Gpio::~Gpio() { }

/*! \brief Returns a copy of the requested Pin
 *
 * Returns a copy of the requested Pin
 *
 * @returns Copy of the requested Pin
 */
Pin Gpio::GetPin(Enums::Gpio::Pins::Number number)
{
	return this->Pins[(UINT16) number];
}

/*! \brief Returns a vector of all the pins on the port
 *
 * Returns a vector of all the pins on the port
 *
 * @returns Vector of all the pins on the port
 */
std::array<Pin, Enums::Gpio::Pins::PinCountPerPort > Gpio::GetPins()
{
	return this->Pins;
}
